package com.landiao.ctrler.management;

import java.math.BigDecimal;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.landiao.common.Constant;
import com.landiao.ctrler.BaseCRUDCtrler;
import com.landiao.entities.Role;
import com.landiao.entities.RoleCommisionRule;
import com.landiao.service.RoleCommisionRuleService;
import com.landiao.service.RoleService;

/**
 * 功能说明:提成配置
 *
 */
@Controller
@RequestMapping("/management/rolecommisionrule")
public class RoleCommisionRuleCtrler extends BaseCRUDCtrler<RoleCommisionRule, String> {

	@Autowired
	private RoleService roleService;
	
	private RoleCommisionRuleService getRoleCommisionRuleService() {
        return (RoleCommisionRuleService) baseService;
    }

	@Override
	public String index(Model model) {
		// TODO Auto-generated method stub
		RoleCommisionRule rule = this.getRoleCommisionRuleService().getMaxEndVal();
		model.addAttribute("maxVal", rule);
		return super.index(model);
	}

	@Override
	public String add(Model model) {
		// TODO Auto-generated method stub
		RoleCommisionRule rule = this.getRoleCommisionRuleService().getMaxEndVal();
		if(rule == null){
			rule = new RoleCommisionRule();
			rule.setEndVal(new BigDecimal("0"));
			Role role = this.roleService.getById(Constant.RoleIdEnum.FXS.toString());
			if(role!=null){
				rule.setRoleId(role.getRoleId());
				rule.setRoleName(role.getName());
			}
//			rule.setRoleId(Constant.RoleIdEnum.FXS.toString());
//			rule.setRoleName(Constant.RoleIdEnum.FXS.getName());
		}
		model.addAttribute("rule", rule);
		return super.add(model);
	}
}
